//
//  UIBarButtonItem+Extensions.swift
//  迷你微博
//
//  Created by Json on 2020/2/13.
//  Copyright © 2020 Json. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    
    /// 创建 UIBarButtonItem
    /// - Parameters:
    ///   - title: title 标题
    ///   - fontSize: fontSize  字体大小
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否返回按钮，如果是加上箭头
    convenience init(title:String, fontSize:CGFloat = 16, target: Any?, action: Selector,isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.gray, highlightedColor: UIColor.orange)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named: imageName), for: UIControl.State(rawValue:0))
            btn.setImage(UIImage(named: imageName+"_highlighted"), for: .highlighted)
            //btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        //self.init实例化UIBarButtonItem
        self.init(customView: btn)
    }
}
